//
//  LNGUNUserNotificationManager.swift
//  HanYuanSchool
//
//  Created by sun on 2022/7/18.
//  Copyright © 2022 hanyuan. All rights reserved.
//

import UIKit

public class LNGUNUserNotificationManager: NSObject {
    public static let shared = LNGUNUserNotificationManager()
    
    public func checkPushNotification(checkNotificationStatus isEnable : ((Bool)->())? = nil) {
        if #available(iOS 10.0, *) {
            UNUserNotificationCenter.current().getNotificationSettings(){ (setttings) in
                switch setttings.authorizationStatus {
                case .authorized:
                    print("enabled notification setting")
                    isEnable?(true)
                case .denied:
                    print("setting has been disabled")
                    isEnable?(false)
                case .notDetermined:
                    print("something vital went wrong here")
                    isEnable?(false)
                case .provisional:
                    isEnable?(false)
                case .ephemeral:
                    isEnable?(false)
                @unknown default:
                    isEnable?(false)
                }
            }
        } else {
            let isNotificationEnabled = UIApplication.shared.currentUserNotificationSettings?.types.contains(UIUserNotificationType.alert)
            if isNotificationEnabled == true {
                print("enabled notification setting")
                isEnable?(true)
            } else {
                print("setting has been disabled")
                isEnable?(false)
            }
        }
    }
}
